package rwt.server.core;

import java.util.Map;

/**
 * Base class for messages.
 */
public class BaseMessage
{
	public static final int INVALID_ID = 0;
	
	private static Map<Class<? extends BaseMessage>, Integer> classToIdMap;
	public static void setClassToIdMap(Map<Class<? extends BaseMessage>, Integer> classToIdMap)
	{
		BaseMessage.classToIdMap = classToIdMap;
	}
	
	public final int id;
	
	public BaseMessage()
	{
		if (!BaseMessage.classToIdMap.containsKey(this.getClass()))
			throw new KeyNotFoundException("Class '" + this.getClass().getName() + "' not found.");
		this.id = BaseMessage.classToIdMap.get(this.getClass());
	}
}
